<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\User as Dbuser;
use think\Db;
use think\Session;

class User extends Controller{


    //账号设置
    public function set_user(){

        $user=Session::get('user_id');
        if (!empty($user)){
            $id=input("id");
            $username=input("username");
            $password=input("password");
            if (!empty($username)&&!empty($password)){
                $Dbuser= new Dbuser();
                $Dbuser->user_update($id,$username,md5($password));
                $fh=[
                  "code"=>1,
                  "message"=>"保存成功"
                ];

            }else{
                $fh=[
                    "code"=>-1,
                    "message"=>"账号密码不能为空"
                ];
            }
            return json_encode($fh);

        }else{

            $this->redirect('admin/login/index');//没登录就重定向到登录页
        }
    }





    public function user_show(){

       $user=Session::get('user_id');
        if (!empty($user)){
            $Dbuser= new Dbuser();
            $result=$Dbuser->user_show();

            return json_encode($result);
        }else{

            $this->redirect('admin/login/index');//没登录就重定向到登录页
        }


    }

}